<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="编号">
                <el-input disabled v-model="ruleForm.id"></el-input>
            </el-form-item>
            <el-form-item label="类型名称" prop="type">
                <el-input v-model="ruleForm.type"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
              <el-button type="danger" @click="resetForm('ruleForm')">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import request from '@/utils/request';
export default {
    name:'EditKindList',
    props:['id','ts'],
    data() {
      return {
        ruleForm: {
          type:''
        },
        rules: {
          type: [
            { required: true, message: '请输入类型', trigger: 'blur' },
          ]
        }
      };
    },
    watch:{
        ts:{
            immediate:true, //初始化时让handler调用一下
            handler(){
                this.fresh()
            }
        }
    },
    methods: {
      fresh(){
        request.get('/api/page/workbench/kind/searchbyid.do',{
        params:{
          id:this.id
        }
      }).then(res=>{
          this.ruleForm.id=res.id,
          this.ruleForm.type=res.type
      })
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            // 发送请求
            this.save()
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
        this.$emit('onClose')
      },
      save(){
        request.post('/api/page/workbench/kind/update.do',{
            id:this.id,
            type:this.ruleForm.type
        }).then(res=>{
            if(res.code==="1"){
                this.$notify.success('修改成功')
                this.$emit('load')
                this.$emit('onConfirm')
            }else{
                this.$notify.error(res.message)
            }
        })
      }
    }
}
</script>

<style>

</style>